﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="/js/header.js"></script>
    <script src="/lib/date/wdatepicker.js"></script>
    <link href="/lib/easyui/default/easyui.css" rel="stylesheet" />
    <script type="text/javascript" src="/lib/easyui/jquery.easyui.min.js"></script>
</head>
<body>
    <div class="data-wrap case">
        <div class="data-tool clearfix">
            <div class="pull-left form-inline ">
                <a class="btn btn-default btn-sm export hide bankDetailExport BankDetail0002" href="javascript:void(0)" data-title="导出">导出</a>
            </div>
            <div class="pull-right">

                <form class="form-inline" id="formSearch" onsubmit="return false;">

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l"><span class="WdateFmtErr">*</span>银行卡号：</label>
                        <input class="form-control wd200" name="cardNumber" type="text" autocomplete="off">

                    </div>

                    <div class="input-group">
                        <label class="input-group-addon m5_l">时间：</label>
                        <input id="d421" class="Wdate wd175" name="startTime" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" autocomplete="off" />--<input id="d422" class="Wdate wd175" name="endTime" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'d421\')}'})" autocomplete="off" />
                    </div>
                    <button type="button" class="btn btn-default btn-sm active" id="btnSearch"><span class="glyphicon glyphicon-search"></span> 搜索</button>
                </form>
            </div>
        </div>

        <div class="data-easyui data-scroll">
            <div class="data-view">
                <div class="data-div-view table-responsive">
                    <table class="table" id="transfercard"></table>
                </div>
            </div>
        </div>
    </div>

    <script src="/js/page/bankdetail.js?v=201907251432"></script>
    <script type="text/javascript">
        var pageSize = 50;

        var autoRefresh = $("input[name='autoRefresh']");
        var cardNumber = $("select[name='cardNumber']");

        
        $(function () {

            $("input[name='startTime']").val(FlashPay.Util.GetDateStr(-1) + " 00:00:00");
            $("input[name='endTime']").val(FlashPay.Util.GetDateStr(0) + " 23:59:59");

            FlashPay.UI.DataAutoHeight();

            $("#btnSearch").click(function () {

                window.currentPage = null;

                doSearch();
            });

            inits();

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/Report/GetBankCardListByCompanyId",
                data: null,
                success: function (response) {
                    if (response.success) {

                        if (response.statusCode == "BankDetail0002") {
                            $("a.BankDetail0002").removeClass("hide");
                        } else {
                            $("a.BankDetail0002").remove();
                        }
                    }
                },
                error: function (e) {
                    cover.Remove();
                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试");
                }
            });

            //FlashPay.UI.DoSearch();

            $(".bankDetailExport").click(function () {

                var query = {}

                query.startTime = $("input[name='startTime']").val();
                query.endTime = $("input[name='endTime']").val();

                var cardNumber = $("input[name='cardNumber']").val();
                if (!FlashPay.Util.isNullOrEmptySpance(cardNumber)) {
                    query.cardNumber = cardNumber;
                }

                var exportName = "银行明细报表({0}-{1})".format(query.startTime, query.endTime);

                FlashPay.UI.Confirm({
                    content: "下载银行明细记录需要花费大量时间,确认要下载吗？",
                    ok: function () {
                        var cover = FlashPay.UI.Mask({
                            obj: $("body"),
                            opacity: 0.5
                        });

                        FlashPay.Util.Ajax({
                            url: '/Report/BankDetailExport',
                            type: 'POST',
                            data: { query: query },
                            success: function (response) {
                                if (response.success) {
                                    cover.Remove();

                                    if (response.rows != null && response.rows.length > 0) {
                                        var body = '<table>';
                                        body += '<tr>';
                                        body += '<td>银行名称</td>';
                                        body += '<td>用户名</td>';
                                        body += '<td>类型</td>';
                                        body += '<td>存、付款后余额</td>';
                                        body += '<td>金额</td>';
                                        body += '<td>客户银行名称</td>';
                                        body += '<td>客户姓名</td>';
                                        body += '<td>客户卡号</td>';
                                        body += '<td>操作时间</td>';
                                        body += '<td>创建时间</td>';
                                        body += '</tr>';

                                        $.each(response.rows, function (i, item) {

                                            body += '<td>' + item.bankName + '</td>';
                                            body += '<td>' + item.cardName + '</td>';
                                            if (item.recordType == 1) {
                                                body += '<td>存款</td>';
                                            } else {
                                                body += '<td>付款</td>';
                                            }
                                            body += '<td>' + FlashPay.Util.FormatNumber(item.balance, 2) + '</td>';
                                            body += '<td>' + FlashPay.Util.FormatNumber(item.amount, 2) + '</td>';
                                            body += '<td>' + item.clientBankName + '</td>';
                                            body += '<td>' + item.clientAccountName + '</td>';
                                            body += '<td>' + item.clientCardNumber + '</td>';
                                            body += '<td>' + item.operatingDateText + '</td>';
                                            body += '<td>' + item.createDBDateText + '</td>';
                                            body += '</tr>';
                                        });
                                        body += '</table>';
                                        var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
                                        excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
                                        excelFile += "<head>";
                                        excelFile += "<!--[if gte mso 9]>";
                                        excelFile += "<xml>";
                                        excelFile += "<x:ExcelWorkbook>";
                                        excelFile += "<x:ExcelWorksheets>";
                                        excelFile += "<x:ExcelWorksheet>";
                                        excelFile += "<x:Name>";
                                        excelFile += "Sheet1";
                                        excelFile += "</x:Name>";
                                        excelFile += "<x:WorksheetOptions>";
                                        excelFile += "<x:DisplayGridlines/>";
                                        excelFile += "</x:WorksheetOptions>";
                                        excelFile += "</x:ExcelWorksheet>";
                                        excelFile += "</x:ExcelWorksheets>";
                                        excelFile += "</x:ExcelWorkbook>";
                                        excelFile += "</xml>";
                                        excelFile += "<![endif]-->";
                                        excelFile += "</head>";
                                        excelFile += "<body>";
                                        excelFile += body;
                                        excelFile += "</body>";
                                        excelFile += "</html>";

                                        var uri = window.URL.createObjectURL(new Blob([excelFile], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }));
                                        var link = document.createElement("a");
                                        link.href = uri;

                                        link.style = "visibility:hidden";
                                        link.download = exportName + ".xlsx";

                                        document.body.appendChild(link);
                                        link.click();
                                        document.body.removeChild(link);
                                    }
                                    else {
                                        cover.Remove();
                                        FlashPay.UI.Tip_warning("暂无记录");
                                    }

                                } else {
                                    cover.Remove();
                                    FlashPay.UI.Tip_warning(response.errorMessage);
                                }
                            },
                            error: function (json) {
                                cover.Remove();
                                FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                            }
                        });
                    }
                });

            });
        });

        $(document).keyup(function (event) {
            var keycode = event.which;
            if (keycode == 13) {
                FlashPay.UI.DoSearch();
            }
        });

        function Tip_success(word) {
            FlashPay.UI.Tip_success(word);
        }

    </script>
</body>
</html>